<template>
	<view>
		<view class="title">智慧城市</view>
		<view class="main">
			<u-form :model="form" label-width="160">
				<u-form-item label="用户名">
					<u-input v-model="form.username"></u-input>
				</u-form-item>
				<u-form-item label="密码">
					<u-input type="password" v-model="form.password"></u-input>
				</u-form-item>
			</u-form>
			<navigator url="/pages/register/register" class="register">
				<text>没有账号?点击注册</text>
			</navigator>
		</view>
		<button @click="submit">登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					username: '',
					password: ''
				}
			};
		},
		methods: {
			submit(){
				this.$request({
					url: '/prod-api/api/login',
					method: 'POST',
					data:{
						...this.form
					}
				}).then(res => {
					if(res.code === 200){
						uni.showToast({
							title:'登录成功'
						})
						setTimeout(() => {
							uni.reLaunch({
								url:'/pages/index/index'
							})
						}, 1000)
					}else{
						uni.showToast({
							icon:'error',
							title:res.msg
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
view{
	padding: 20rpx;
	.title{
		display: flex;
		justify-content: center;
		align-items: center;
		color: #2979ff;
		font-size: 45rpx;
	}
	.main{
		padding: 20rpx;
		position: relative;
		.register{
			width: fit-content;
			display: flex;
			justify-content: end;
			color: #2979ff;
			font-size: 26rpx;
			position: absolute;
			right: 0;
			bottom: 0;
		}
	}
	button{
		width: 200rpx;
		height: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #2979ff;
		color: white;
		margin-top: 50rpx;
	}
}
</style>
